"""
@Time : 2021/7/4 11:53 AM 
@Author : Xiaoming
"""

import pymongo
from config.configGetter import settings


class MongoClient:
    def __init__(self, database=None, collection=None):
        self.client = pymongo.MongoClient(settings.mongo_uri)
        if database is not None:
            db = self.client[database]
        else:
            db = self.client[settings.mongodb_name]
        if collection is not None:
            self.collect = db[collection]
        else:
            self.collect = db[settings.collection]

    def insert_one(self, item_json: str) -> None:
        self.collect.insert_one(item_json)

    def get_one(self):
        return self.collect.find_one()

